﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace dsjsports
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.MouseLeftButtonDown += new MouseButtonEventHandler(Window1_MouseLeftButtonDown);

            DataBaseSportsmenList.SynchronizerSet(synchronizer);
            DataBaseSportsmenList1.SynchronizerSet(synchronizer);
        }

        private static Synchronizer synchronizer = new Synchronizer();

        private void turn_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = System.Windows.WindowState.Minimized;
        }
        private void expand_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == System.Windows.WindowState.Normal)
            {
                this.WindowState = System.Windows.WindowState.Maximized;
                MaxI.Visibility = System.Windows.Visibility.Visible;
                MinI.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                this.WindowState = System.Windows.WindowState.Normal;
                MaxI.Visibility = System.Windows.Visibility.Collapsed;
                MinI.Visibility = System.Windows.Visibility.Visible;
            }
        }
        private void close_Click(object sender, RoutedEventArgs e)
        {
            synchronizer.SynchronizerTreadAbort();
            this.Close();
        }

        void Window1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!isWiden)
                this.DragMove();
        }

        bool isWiden = false;

        private void window_initiateWidenHorizontalRight(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = true;
        }
        private void window_endWidenHorizontalRight(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = false;

            Rectangle rect = (Rectangle)sender;
            rect.ReleaseMouseCapture();
        }
        private void window_WidenHorizontalRight(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;
            if (isWiden)
            {
                rect.CaptureMouse();
                double newWidth = e.GetPosition(this).X + 5;
                if (newWidth > 0) 
                    this.Width = newWidth;
            }
        }

        private void window_initiateWidenHorizontalLeft(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = true;
        }
        private void window_endWidenHorizontalLeft(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = false;

            Rectangle rect = (Rectangle)sender;
            rect.ReleaseMouseCapture();
        }
        private void window_WidenHorizontalLeft(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;
            if (isWiden)
            {
                rect.CaptureMouse();

                double newWidth = e.GetPosition(this).X - 5;
                this.Left += newWidth;
                this.Width = this.ActualWidth - newWidth;
            }
        }

        private void window_initiateWidenVerticalTop(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = true;
        }
        private void window_endWidenVerticalTop(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = false;

            Rectangle rect = (Rectangle)sender;
            rect.ReleaseMouseCapture();
        }
        private void window_WidenVerticalTop(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;
            if (isWiden)
            {
                rect.CaptureMouse();
                double newHeight = e.GetPosition(this).Y + 5;
                this.Top += newHeight;
                this.Height = this.ActualHeight - newHeight;
            }
        }

        private void window_initiateWidenVerticalBottom(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = true;
        }
        private void window_endWidenVerticalBottom(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isWiden = false;

            Rectangle rect = (Rectangle)sender;
            rect.ReleaseMouseCapture();
        }
        private void window_WidenVerticalBottom(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;
            if (isWiden)
            {
                rect.CaptureMouse();
                double newHeight = e.GetPosition(this).Y + 5;
                if (newHeight > 0) this.Height = newHeight;
            }
        }

        private bool isOpen = true;


    }
}


